package com.seata.demo.service.impl;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seata.demo.mapper.OrderTblMapper;
import com.seata.demo.model.OrderTbl;
import com.seata.demo.service.OrderService;
import com.seata.demo.util.res.Resp;

import lombok.extern.slf4j.Slf4j;

/**
* @comments
* @author  zg
* @date 2021年2月9日
*/
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    
    @Autowired
    private OrderTblMapper orderTblMapper;

    @Override
    public Resp<?> create(String userId, String commodityCode, int commodityCount, BigDecimal commodityPrice, BigDecimal orderPrice) {
        OrderTbl order = new OrderTbl();
        order.setCommodityCode(commodityCode);
        order.setCommodityPrice(commodityPrice);
        order.setCount(commodityCount);
        order.setMoney(orderPrice);
        order.setUserId(userId);
        if(orderTblMapper.insert(order) > 0) {
            log.info("创建订单成功！");
            return Resp.success();
        }
        
        return Resp.error();
    }

}
